package rpcservice

import (
    "rpcserver/lib/thrift"
    "net"
)

type RpcService struct {
    handle  ProtoRpcService
}

func NewRpcService(h ProtoRpcService) *RpcService {
    return &RpcService{handle:h}
}

func (sv *RpcService) Start(host, port string) error {
    transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
    protocolFactory  := thrift.NewTBinaryProtocolFactoryDefault()

    serverTranport, err := thrift.NewTServerSocket(net.JoinHostPort(host, port))
    if err != nil {
        return  err
    }

    processor := NewProtoRpcServiceProcessor(sv.handle)
    server := thrift.NewTSimpleServer4(processor, serverTranport, transportFactory, protocolFactory)

    return server.Serve()
}
